<!-- 联系我们 -->
<template>
  <div class="contact-us">
    <div class="header">
      <div>
        <el-button type="text" icon="el-icon-arrow-left" style="color: #F4A780; font-size: 16px" @click="goBack">
          <span>AI助手</span>
        </el-button>
      </div>
      <div class="right">
        <el-button type="text" icon="el-icon-more"></el-button>
        <el-button type="text" icon="el-icon-s-help"></el-button>
      </div>
    </div>
    <div class="content">
      <p class="message">请留下问题描述，我们的智能助手会为您解决，如有其他问题可以致电400-123-4567。感谢您的支持！</p>
      <el-form :model="formData" label-width="100px">

        <el-form-item label="问题描述：">
          <el-input type="textarea" v-model="question" placeholder="请输入您遇到的问题"></el-input>
        </el-form-item>
      </el-form>
      <!-- 其他代码 -->
      <div v-if="aiResponse" class="ai-response">
        <h3>AI 回复:</h3>
        <p>{{ aiResponse }}</p>
      </div>
      <!-- 其他代码 -->
      <el-button type="primary" class="submit-btn" @click="commit">提交</el-button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      formData: {
        name: '',
        phone: '',
        problem: ''
      },
      question: '',
      aiResponse: '',
    }
  },
  methods: {
    commit() {
      this.axios.post("http://localhost:9701/web/ai/send", { question: this.question }).then(res => {
            this.aiResponse = res.data; // 假设 AI 的回复在 res.data.data 中
          })
          .catch(error => {
            console.error("Error sending question to AI:", error);
            this.aiResponse = "无法获取 AI 回复";
          });
    },
    goBack() {
      this.$router.go(-1);
    },
  }
}
</script>

<style scoped>
.content {
  border-top: 1px solid #F4A780;
}

.right {
  display: flex;
  border: 1px solid #F4A780;
  padding: 5px 5px;
  border-radius: 15px;
}

.right button {
  color: #F4A780;
  padding: 0 5px;
  font-size: 18px;
}

.contact-us {
  width: 390px;
  margin: 0 auto;
}

.header {
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.message {
  margin-bottom: 20px;
  font-size: 14px;
  color: #96a8be;
}

.submit-btn {
  width: 100%;
  margin-top: 20px;
}
</style>